﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SnowDAL;

namespace Snow.Setting
{
    public partial class RecommendSetting : System.Web.UI.Page
    {
        private UserDAL _dal = new UserDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitMale();

                InitFemale();
            }
        }

        private void InitMale()
        {
            gvBoy.DataSource = _dal.QueryCommend("M");
            gvBoy.DataBind();
        }

        private void InitFemale()
        {
            gvGirl.DataSource = _dal.QueryCommend("F");
            gvGirl.DataBind();
        }

        protected void gvBoy_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (_dal.DeleteCommend(e.Keys["uid"].ToString()) > 0)
                InitMale();
        }

        protected void gvGirl_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (_dal.DeleteCommend(e.Keys["uid"].ToString()) > 0)
                InitFemale();
        }

        protected void btnAddBoy_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBoy.Text.Trim()) && _dal.CreateCommend(txtBoy.Text.Trim(), "M") > 0)
                InitMale();
        }

        protected void btnAddGirl_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtGirl.Text.Trim()) && _dal.CreateCommend(txtGirl.Text.Trim(), "F") > 0)
                InitFemale();
        }



    }
}